package cn.acyou.leo.user.controller;

import cn.acyou.leo.framework.commons.PageQuery;
import cn.acyou.leo.framework.model.PageData;
import cn.acyou.leo.framework.model.Result;
import cn.acyou.leo.user.entity.Student;
import cn.acyou.leo.user.mapper.StudentMapper;
import cn.acyou.leo.user.service.StudentService;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fangyou
 * @version [1.0.0, 2021/7/29]
 */
@Slf4j
@RestController
@RequestMapping("/student")
@Api(value = "学生", description = "学生的增删改查", tags = "学生接口")
public class StudentController {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "page", method = {RequestMethod.GET})
    @ApiOperation("测试分页")
    public Result<PageData<Student>> studentsPage(Integer pageNum, Integer pageSize) {
        PageData<Student> convertType =  PageQuery.startPage(pageNum, pageSize).selectMapper(studentMapper.selectAll());
        return Result.success(convertType);
    }
    @RequestMapping(value = "get", method = {RequestMethod.GET})
    @ApiOperation("get")
    public Result<?> get(Long id) {
        JSONObject jo = new JSONObject();
        jo.put("id", id);
        jo.put("name", "张飞");
        Student stu = studentService.getById(jo, jo);
        return Result.success(stu);
    }
    @RequestMapping(value = "get2", method = {RequestMethod.GET})
    @ApiOperation("get2")
    public Result<?> get2(Long id) {
        JSONObject jo = new JSONObject();
        jo.put("id", id);
        jo.put("name", "张飞");
        List<String> list = Lists.newArrayList("111","222","333");
        Student stu = studentService.getById(jo, list);
        return Result.success(stu);
    }
}
